package com.example.controller;

import com.example.pojo.OutMaterials;
import com.example.pojo.PageBean;
import com.example.pojo.Result;
import com.example.service.OutMaterialsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@RequestMapping("/out1")
public class OutMaterialsController {

    @Autowired
    private OutMaterialsService outMaterialsService;

    @GetMapping
    public Result select(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                         String mname, @RequestParam(defaultValue = "0") int num,
                         @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageBean pageBean = outMaterialsService.page(page, pageSize, mname, num,begin, end);
        return Result.success(pageBean);
    }

    @DeleteMapping("/{id}")
    public Result deletes(@PathVariable int [] id){
        outMaterialsService.delete(id);
        return Result.success();
    }
    @PostMapping
    public Result dd(@RequestBody OutMaterials outMaterials){
        System.out.println(outMaterials.getId());
        outMaterialsService.delete(new int[]{outMaterials.getId()});
        return Result.success();
    }
}
